/** 
 * Description:首页分类管理 
 * Date:2013-1-11
 * Author:Along	
*/
package com.community.shopping.service.logic;

import java.util.List;
import com.community.shopping.dao.IndexItemDao;
import com.community.shopping.domain.GoodsType;
import com.community.shopping.domain.IndexItem;


public class IndexItemManager {
	public IndexItemDao indexItemDao;
	/**
	 * @param indexItemDao the indexItemDao to set
	 */
	public void setIndexItemDao(IndexItemDao indexItemDao) {
		this.indexItemDao = indexItemDao;
	}
	
	/**
	 * 保存一行indexItem
	*/
	public void save(IndexItem indexItem){
		indexItemDao.save(indexItem);
	}
	/**
	 * 删除一行indexItem
	*/
	public void delete(IndexItem indexItem){
		indexItemDao.delete(indexItem);
	}
	
	public List<IndexItem> getIndexItem(Integer shopId) {  		
		 return indexItemDao.getIndexItemByShopId(shopId);
	}
	/**
	 * 根据条件下查询
	*/
	public List getIndexItemDao(String sql){
		return indexItemDao.getIndexItem(sql);
	}
	
	/**
	 * 根据类别查询
	*/
	public IndexItem getIndexItemByType(GoodsType type){
		 IndexItem item=new IndexItem();
		 List items=indexItemDao.getIndexItem("goodsType.id='"+type.getId()+"'  order by goodsType.sort");
		 if(items.size()>0)
		 {
			 item=(IndexItem)items.get(0);
		 }else
		 {
			 item.setGoodsType(type);	
			 item.setBanerImg("/images/admin/base_overlay_bg.png");
			 item.setFirstImg("/images/admin/base_overlay_bg.png");
			 item.setEndImg("/images/admin/base_overlay_bg.png");
			 this.save(item);
		 }
		 return item;
	}
	
	public IndexItem getIndexItemById(Integer id){
		return indexItemDao.getIndexItem(id);
	}

}
